import * as z from "zod";

export  const userFormSchema = z.object({
    name:z.string().min(2,'地址至少需要2个字符'),
    phone: z
        .string()
        .regex(/^\+?\d{10,15}$/, "请输入有效的手机号码"),
    address: z.string().min(5, "地址至少需要5个字符"),
    birthDate: z.date() .min(new Date("2024-01-01"), { message: "日期不能早于 1924 年 1 月 1 日" })
        .max(new Date(), { message: "日期不能晚于当日" }),
    wechat: z.string().min(3, "微信号至少需要3个字符"),
    gender: z.enum(["male", "female"]),
    role: z.enum(["user", "admin"]),
    avatar: z
        .any()
        .optional()
        .refine((file) => file instanceof File, "请上传头像")
        .refine(
            (file) => file?.size <= 5 * 1024 * 1024,
            "头像文件大小不能超过5MB"
        )
        .refine(
            (file) => ["image/jpeg", "image/png"].includes(file?.type),
            "仅支持JPEG或PNG格式的头像"
        ),
    otherImages: z

        .array(z.any())
        .optional()
        .refine(
            (files) => !files || files.every((file: File) => file instanceof File),
            "请上传有效的图片文件"
        )
        .refine(
            (files) => !files || files.every((file: File) => file.size <= 5 * 1024 * 1024),
            "每张图片大小不能超过5MB"
        )
        .refine(
            (files) =>
                !files || files.every((file: File) =>
                    ["image/jpeg", "image/png"].includes(file.type)
                ),
            "仅支持JPEG或PNG格式的图片"
        )
        .optional(),
    selfieVideo: z
        .any()
        .optional()
        .refine((file) => !file ||file instanceof File, "请上传自拍视频")
        .refine(
            (file) => !file ||file.size <= 50 * 1024 * 1024,
            "视频文件大小不能超过50MB"
        )
        .refine(
            (file) =>!file || ["video/mp4", "video/webm"].includes(file?.type),
            "仅支持MP4或WEBM格式的视频"
        ),
});